package com.happe.foodeasy.manage.helper;

import com.happe.foodeasy.manage.commodity.entity.CommodityTypeEntity;
import com.happe.foodeasy.manage.commodity.entity.ProvinceInfoEntity;
import com.happe.foodeasy.manage.common.entity.ManageNavDirectoryEntity;
import com.happe.foodeasy.manage.service.CommodityTypeService;
import com.happe.foodeasy.manage.service.ManageNavDirectoryService;
import com.happe.foodeasy.manage.service.ProvinceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * This class is used to retrieve data from database, and the data are
 * used in many places.
 * Created by Administrator on 2016/8/11.
 */
@Component("retrieveDataHelper")
public class RetrieveDataHelper {
    private static final String COMMODITY_TYPE_LIST_KEY = "commodityTypeList";
    private static final String PROVINCE_LIST_KEY = "provinceList";

    @Autowired
    private ManageNavDirectoryService manageNavDirectoryService;
    @Autowired
    private CommodityTypeService commodityTypeService;
    @Autowired
    private ProvinceInfoService provinceInfoService;

    /*这个方法用于得到管理员界面的所有导航条目*/
    public List<ManageNavDirectoryEntity> retrieveAllNavDirectory() {
        return manageNavDirectoryService.select();
    }

    public RetrieveDataHelper addAllCommodityTypeInMAV(ModelAndView modelAndView){
        List<CommodityTypeEntity> allTypes = commodityTypeService.selectAllCommodityType();
        modelAndView.addObject(COMMODITY_TYPE_LIST_KEY, allTypes);
        return this;
    }

    public RetrieveDataHelper addAllProvinceInMAV(ModelAndView modelAndView){
        List<ProvinceInfoEntity> allProvinces = provinceInfoService.selectAllProvinces();
        modelAndView.addObject(PROVINCE_LIST_KEY, allProvinces);
        return this;
    }
}
